package com.yjz.zpay.utils;

import android.text.format.Time;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 * Created by yjz on 2018/5/11.
 */
public class TimesUtils {

    public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");


    private TimesUtils() {
        throw new AssertionError();
    }

    /**
     * long time to string
     *
     * @param timeInMillis
     * @param dateFormat
     * @return
     */
    public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
        return dateFormat.format(new Date(timeInMillis));
    }




    /**
     * long time to string, format is {@link #DEFAULT_DATE_FORMAT}
     *
     * @param timeInMillis
     * @return
     */
    public static String getTime(long timeInMillis) {
        return getTime(timeInMillis, DEFAULT_DATE_FORMAT);
    }

    /**
     * get current time in milliseconds
     *
     * @return
     */
    public static long getCurrentTimeInLong() {
        return System.currentTimeMillis();
    }

    /**
     * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}
     *
     * @return
     */
    public static String getCurrentTimeInString() {
        return getTime(getCurrentTimeInLong());
    }

    /**
     * get current time in milliseconds
     *
     * @return
     */
    public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
        return getTime(getCurrentTimeInLong(), dateFormat);
    }


    public static String getMonth() {
        Time time = new Time("GMT+8");
        time.setToNow();
        int month = time.month + 1;

        if (month < 10) {
            return "0" + month;
        } else {
            return month + "";
        }

    }

    public static int getCurrentMonth() {
        Time time = new Time("GMT+8");
        time.setToNow();
        int month = time.month;
        return month;
    }

    public static int getCurrentYear() {
        Time time = new Time("GMT+8");
        time.setToNow();
        int month = time.year;
        return month;
    }

    public static int getCurrentDay() {
        Time time = new Time("GMT+8");
        time.setToNow();
        int month = time.monthDay;
        return month;
    }


}
